﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

/// <summary>
/// This implementation was based on the code sample provided here:
/// http://passwordadvisor.com/CodeAspNet.aspx
/// </summary>
namespace CommerceForUmbraco.usercontrols
{
    public enum PasswordScore
	{
	    Blank = 0,
	    VeryWeak = 1,
	    Weak = 2,
	    Medium = 3,
	    Strong = 4,
	    VeryStrong = 5
	}


    public class PasswordAdvisor
    {
        public static PasswordScore CheckStrength(string password)
        {
            int score = 1;

            if (password.Length < 1)
                return PasswordScore.Blank;
            if (password.Length < 4)
                return PasswordScore.VeryWeak;

            if (password.Length >= 6)
                score++;
            if (password.Length >= 12)
                score++;
            if (Regex.IsMatch(password, @"/\d+/", RegexOptions.ECMAScript))
                score++;
            if (Regex.IsMatch(password, @"/[a-z]/", RegexOptions.ECMAScript) &&
                Regex.IsMatch(password, @"/[A-Z]/", RegexOptions.ECMAScript))
                score++;
            if (Regex.IsMatch(password, @"/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript))
                score++;

            return (PasswordScore)score;
        }
    }
}